<?PHP

namespace LibAES;

class Aes
{
    public $key = '';
 
    public $iv = '';
 
    public function __construct($config)
    {
        foreach($config as $k => $v){
            $this->$k = $v;
        }
    }
    //加密
    public function aesEn($data){
     return  base64_encode(openssl_encrypt($data, $this->method,$this->key, OPENSSL_RAW_DATA , $this->iv));  
    }
 
    //解密
    public function aesDe($data){
     return openssl_decrypt(base64_decode($data),  $this->method, $this->key, OPENSSL_RAW_DATA, $this->iv);
    }

//url base64编码
public function urlsafe_b64encode($string) {
    $data = base64_encode($string);
    $data = str_replace(array('+','/','='),array('-','_',''),$data);
    return $data;
}
//url base64解码
public function urlsafe_b64decode($string) {
    $data = str_replace(array('-','_'),array('+','/'),$string);
    $mod4 = strlen($data) % 4;
    if ($mod4) {
	$data .= substr('====', $mod4);
    }
    return base64_decode($data);
}
}

